<template>
	<view class='issue'>
		<view class="issue-head">
			<slot name="headPic"></slot>
			<image :src="headPicValue" class="issue-head-pic" mode=""></image>
			<text class="issue-head-title">{{headTitleValue.slice(0,5)}}</text>
			<view class="issue-head-star-box" v-if="readOnly">
				<image v-for="(item,index) in starsMax" :key="index" :src="(index+1)>score?starDefault:starActive" :class="score==index+1?'active':''" mode=""></image>
			</view>
			<view class="issue-head-star-box" v-else>
				<image v-for="(item,index) in starsMax" :key="index" :src="(index+1)>score?starDefault:starActive" :class="score==index+1?'active':''" mode="" @click="setScore(index+1)"></image>
			</view>
		</view>
		 <textarea :disabled="readOnly" v-model="textareaValue" :placeholder="textareaPlaceholder"/>
		 <view class="issue-btn-box" v-if="!readOnly">
		 	<button class="submit-btn base-bg" type="primary" @click="doSubmit">{{submitText}}</button>
			<slot name="submit"></slot>
		 </view>
	</view>
</template>
<script>
	export default {
		data(){
			return{
				textareaValue:'',
				score:0
			}
		},
		props:{
			headPicValue:{
				type:String,
				default:require('@/static/img/st_pic.png')
			},
			headTitleValue:{
				type:String,
				default:"服务评价"
			},
			starsMax:{ // 星星最大个数
				type:[String,Number],
				default:5,
			},
			starDefault:{ //未选中
				type:String,
				default:require('@/static/img/st_star.png'),
			},
			starActive:{
				type:String,
				default:require('@/static/img/st_star_active.png'),
			},
			defScore:{  //默认分数
				type:Number,
				default:0
			},
			textareaPlaceholder:{
				type:String,
				default:"请对本次服务进行评价下!"
			},
			readOnly:{ //只读模式
				type:[Boolean],
				default:false
			},
			defTextareaValue:{
				type:String,
				default:""
			},
			submitText:{
				type:String,
				default:"发布",
			}
		},
		mounted() {
			this.score=this.defScore
			this.textareaValue=this.defTextareaValue
		},
		methods: {
			/**
			 * @name 设置分数
			 */
			setScore(score){
				this.score=score
				this.$emit("scoreChange",score)
			},
			
			/**
			 * @name 提交
			 */
			doSubmit(){
				this.$emit('submit',this.score,this.textareaValue)
			}
		}
	}
</script>
<style lang='scss'>
	$backgroundC:#f9f9f9;
	$borderColor:#f5f5f5;
	$white:#ffffff;
	$fontSize:28upx;
	
	.issue {
		background-color: $backgroundC;
		
		&-head{
			background-color: $white;
			height: 100upx;
			border-top: 1upx solid $borderColor;
			border-bottom: 1upx solid $borderColor;
			padding: 0 25upx;
			
			&-pic{
				width: 70upx;
				height: 70upx;
				border-radius: 50%;
				vertical-align: middle;
				margin-right: 17upx;
			}
			&-title{
				line-height: 100upx;
				font-size: 30upx;
				vertical-align: middle;
				margin-right: 35upx;
			}
			
			&-star-box{
				display: inline-block;
				
				image{
					width: 32upx;
					height: 32upx;
					vertical-align: middle;
					margin-right: 14upx;
				}
				image.active{
					animation: star_move ease-in 1 1s,star_rotate ease 1.5s infinite 1s;
				}
			}
		}
		textarea{
			width: 100%;
			height: 420upx;
			background-color: $white;
			font-size: $fontSize;
			color: #898989;
			padding: 24upx;
			box-sizing: border-box;
			line-height: 40upx
		}
		&-btn-box{
			padding: 54upx 30upx;
			
			button{
				width: 100%;
				height: 80upx;
				border-radius: 80upx;
				font-size: $fontSize;
				background-color: #3682FF;
				line-height: 80upx
			}
		}
	}
	
	@keyframes star_move{
		from{
			width: 50upx;
			height: 50upx;
			transform: rotate(180deg)
		}
		to{
			width: 32upx;
			height: 32upx;
			transform: rotate(0)
		}
	}
	@keyframes star_rotate{
		0%{
			transform: rotateY(360deg)
		}
		100%{
			transform: rotateY(180deg)
		}
	}
</style>
